<script setup lang="ts">
import { ref, watch, onMounted } from "vue";

// 定义选项的类型
interface RadioOption {
  value: string | number;
  label: string;
}

// 为 props 添加类型定义
const props = defineProps<{
  modelValue?: string | number | null;
  option?: RadioOption[];
  disabled?: boolean;
}>();

const emit = defineEmits<{
  (e: 'update:modelValue', value: string | number): void;
}>();

const radio = ref<string | number>(0);

onMounted(() => {
  radio.value = props.modelValue ?? 0;
});

// 为 val 添加类型注解
function change(val: string | number) {
  emit("update:modelValue", val);
}

watch(
  () => props.modelValue,
  (val) => {
    radio.value = val ?? 0;
  },
  {
    deep: true
  }
);
</script>
